<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>{{ SYSTEM_NAME }} - 任务创建</title>
    <link rel="stylesheet" href="{{ LAYUI_PATH }}layui/css/layui.css" media="all">
    <script src="https://res.mapo.cc/static/js/axios.min.js"></script>
</head>
<body>
    <div class="layui-card" id="app">
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form" action="" lay-filter="component-form-element">
                    <div class="layui-row layui-col-space10 layui-form-item">
                        <div class="layui-col-lg6">
                            <label class="layui-form-label">任务名称:</label>
                            <div class="layui-input-block">
                                <input type="text" name="taskname" lay-verify="required" placeholder=""
                                    autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-lg6">
                            <label class="layui-form-label">任务等级:</label>
                            <div class="layui-input-block">
                                <select name="level" lay-verify="required" lay-filter="aihao">
                                    <option value=""></option>
                                    <option value="1">Lv1-黄界</option>
                                    <option value="2">Lv2-玄界</option>
                                    <option value="3">Lv3-地界</option>
                                    <option value="4">Lv4-天界</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <label class="layui-form-label">任务来源:</label>
                            <div class="layui-input-block">
                                <select name="source" lay-verify="required" lay-filter="aihao">
                                    <option value=""></option>
                                    <option value="阳光守护">阳光守护</option><option value="彩票赌博">彩票赌博</option><option value="三大运营商">三大运营商</option><option value="临时任务">临时任务</option><option value="分析任务">分析任务</option><option value="动作类">动作类</option>                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">任务期限:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="start" class="layui-input" lay-verify="required"
                                    id="test-laydate-type-datetime1" placeholder="yyyy-MM-dd HH:mm:ss">
                            </div>
                            <div class="layui-input-inline">
                                <input type="text" name="end" class="layui-input" lay-verify="required"
                                    id="test-laydate-type-datetime2" placeholder="yyyy-MM-dd HH:mm:ss">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">任务状态:</label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" value="1" title="进行中">
                            <input type="radio" name="status" value="2" title="暂停中">
                            <input type="radio" name="status" value="3" title="已停止">
                            <input type="radio" name="status" value="4" title="已结束">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">任务说明:</label>
                        <div class="layui-input-block">
                            <textarea name="other" placeholder="" lay-verify="required"
                                class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <label class="layui-form-label">在线文档:</label>
                            <div class="layui-input-block">
                                <input type="text" name="taskurl" lay-verify="required" placeholder=""
                                    autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">参与人员:</label>
                        <div>
                            <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate"></table>
                        </div>

                    </div>
                    <div class="layui-form-item layui-layout-admin">
                        <div class="layui-input-block">
                            <div class="layui-footer" style="left: 0;">
                                <button class="layui-btn" lay-submit="Upload" lay-filter="Upload">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script src="{{ LAYUI_PATH }}layui/layui.js"></script>
    <script>
        {#window.open("about:blank","_self").close()#}
        layui.config({
            base: '{{ LAYUI_PATH }}' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'laydate','table'], function () {
            var $ = layui.$
                , admin = layui.admin
                , table = layui.table
                , element = layui.element
                , form = layui.form
                , laydate = layui.laydate;
            table.render({
      elem: '#test-table-operate'
      ,url: '/user/getObjUsers'
      ,width: 350
      ,height: 332
      ,cols: [[
        {type:'checkbox', fixed: 'left'}
        ,{field:'id', width:80, title: 'ID', sort: true, fixed: 'left'}
        ,{field:'name', width:80, title: '姓名'}
      ]]
      ,page: true
    });

    //监听表格复选框选择
    table.on('checkbox(test-table-operate)', function(obj){
      console.log(obj)
    });


    var $ = layui.$, active = {
      getCheckData: function(){ //获取选中数据
        var checkStatus = table.checkStatus('test-table-operate')
        ,data = checkStatus.data;
        layer.alert(JSON.stringify(data));
      }
    };

    $('.test-table-operate-btn .layui-btn').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });

            laydate.render({
                elem: '#test-laydate-type-datetime1'
                , type: 'datetime'
                , trigger: 'click'
            });
            laydate.render({
                elem: '#test-laydate-type-datetime2'
                , type: 'datetime'
                , trigger: 'click'
            });

            form.render(null, 'component-form-element');
            element.render('breadcrumb', 'breadcrumb');
            window.lock = false;
            form.on('submit(Upload)', function (data) {
                if (window.lock) { return false; }
                window.lock = true;
                var OnPeople = '|';
                var chks = $("#onpeople input:checked");

                for (var i = 0; i < chks.length; i++) {
                    if (!this.OnPeople) {
                        this.OnPeople = chks[0].name;
                        continue;
                    }
                    this.OnPeople += "|" + chks[i].name;
                    console.log(this.OnPeople);
                }
                data.field.people = this.OnPeople;
                var start = new Date(data.field.start);
                var end = new Date(data.field.end);
                console.log(data.field.start, data.field.end);
                data.field.start = start / 1000;//时间转换
                data.field.end = end / 1000;//时间转换
                $.ajax({
                    //ajax数据准备
                    type: 'POST',
                    url: '/Console/AddTask',
                    data: data.field,
                    dataType: 'json',
                    beforeSend: function () {
                        //开启锁定
                        window.lock = true;
                        window.loading = parent.layer.msg('正在创建...', { icon: 16, time: false, shade: 0.3 });
                    },
                    success: function (res) {
                        switch (res.code) {
                            case 200:
                                parent.layer.msg(res.msg, { icon: 1 });
                                document.cookie="AddTask=true";
                                setTimeout(function () {
                                    var me = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(me);
                                }, 1500);
                                break;
                            case 400:
                                parent.layer.msg(res.msg, { icon: 2 });
                                break;
                            default:
                                parent.layer.msg('未知的返回?', { icon: 3 });
                                break;
                        }
                        console.log(res);
                    },
                    error: function (err) {
                        parent.layer.msg('网络错误,请检查后重试!', { icon: 2 });
                        //console.log(err);
                    },
                    complete: function () {
                        parent.layer.close(window.loading);
                        window.lock = false;//关闭锁定
                    }

                });


                return false;
            });
        });
    </script>
</body>
</html>